﻿@using A2.ERP.Models
@{
    List<v_User> dataList = ViewBag.DataList;
}

<section id="SysUserManager">
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>账号</th>
                <th>姓名</th>
                <th>权限组</th>
                <th>一级类型</th>
                <th>二级类型</th>
                <th>状态</th>
                <th>电话</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            @foreach (v_User item in dataList)
            {
                <tr>
                    <td>@item.UserName</td>
                    <td>@item.RealName</td>
                    <td>@item.GroupName</td>
                    <td>@item.SubClassName</td>
                    <td>@item.TypeName</td>
                    <td>
                        @Html.Raw(item.State == "Y"
                       ? @"<i class='icon SkyUI icon-check-circle text-success'></i>"
                        : @"<i class='icon SkyUI icon-close-circle text-danger'></i>")
                    </td>
                    <td>@item.Tel</td>
                    <td>
                        <a data-route="\setting\EditUser\@item.UserName" class="btn btn-primary btn-sm text-white">
                            <i class="icon SkyUI icon-edit"></i>
                            编辑
                        </a>
                        <a data-route="\setting\CheckUser\@item.UserName" class="btn btn-success btn-sm text-white">
                            <i class="icon SkyUI icon-search"></i>
                            查看
                        </a>
                        @{
                            var stateProps = new string[] { "btn-danger", "icon-close", "停用" };
                            if (item.State == "N")
                            {
                                stateProps[0] = "btn-warning";
                                stateProps[1] = "icon-check";
                                stateProps[2] = "启用";
                            }
                        }
                        <a data-id="@item.UserName" data-state="@item.State" class="btn @stateProps[0] btn-sm text-white disable-user" data-target="#disableUserModal" data-toggle="modal">
                            <i class="icon SkyUI @stateProps[1]"></i>
                            @stateProps[2]
                        </a>
                    </td>
                </tr>
                            }
        </tbody>
    </table>
    <div class="modal fade" id="disableUserModal" tabindex="-1" role="dialog" aria-labelledby="sysUserModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">确定要改边用户状态吗?</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    确定要改边用户状态吗?
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                    <button type="button" class="btn btn-primary btn-submitDisableUser">Sure</button>
                </div>
            </div>
        </div>
    </div>
</section>

<script>
    (function () {
        var cureentUserId = '';
        var currentUserState = 'N';
        var $disableUserModal = $('#disableUserModal');

        var changeUserState = function (id, state) {
            $.post('/setting/changeUserState',
                {
                    id: id,
                    state: state
                },
                function (result) {
                    $('.modal').modal('hide');
                    $tab.reloadTab('#SysUserManager');
                });
        }

        $('.btn-submitDisableUser').on('click', function () {
            changeUserState(cureentUserId, currentUserState);
        });

        $('.disable-user').on('click', function () {
            cureentUserId = this.getAttribute('data-id') || '';
            currentUserState = this.getAttribute('data-state') || 'N';
        });



    }());
</script>